define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'paotui/posterextract/index' + location.search,
                    multi_url: 'paotui/posterextract/multi',
                    import_url: 'paotui/posterextract/import',
                    table: 'paotui_poster_extract',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'poster_id', title: __('骑手ID')},
                        {field: 'poster_name', title: __('骑手姓名'), operate: 'LIKE'},
                        {field: 'type', title: __('提现类型'), operate: false,formatter: Controller.api.formatter.type},
                        {field: 'message',align:'left', title: __('提现信息'), operate: false,formatter: Controller.api.formatter.message},
                        {field: 'extract_price', title: __('申请提现金额'), operate:'BETWEEN'},
                        {field: 'fee_scale', title: __('提现手续费（%）'), operate: false},
                        {field: 'true_price', title: __('实际到账金额（扣除手续费）'), operate:'BETWEEN'},

                        {field: 'createtime', title: __('申请时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'checktime', title: __('审核时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('状态'),searchList: {"1": __('已通过'), "0": __('待审核'), "-1": __('未通过')},formatter: Controller.api.formatter.status},
                        {field: 'fail_msg', title: __('未通过原因'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'),align:'left', table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('确认通过'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'paotui/posterextract/succ',
                                    confirm: '确认同意提现吗？',
                                    success: function (data, ret) {
                                        table.bootstrapTable('refresh', {});
                                    },
                                    visible: function (row) {
                                        if(row['status'] != 0){
                                            return false;
                                        }
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    },
                                },
                                {
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status == 0){
                                            return true;
                                        }
                                        return false;
                                    },
                                    name: 'detail',
                                    text: __('拒绝'),
                                    classname: 'btn btn-danger btn-xs btn-detail btn-dialog',
                                    url: 'paotui/posterextract/cancel',
                                    success: function (data, ret) {
                                        table.bootstrapTable('refresh');
                                    },
                                },
                                {
                                    visible:function (row) {
                                        if(row['status'] == -1 || row['status'] == 0){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                    name: 'del',
                                    title: __('删除'),
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    confirm: '确认删除吗？',
                                    icon: 'fa fa-trash-o',
                                    url: 'paotui/posterextract/del',
                                    success: function (data, ret) {
                                        table.bootstrapTable('refresh');
                                    },
                                }
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });


            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        cancel: function () {
            Controller.api.bindevent();
        },
        api: {
            formatter:{
                status:function (value, row, index) {
                    switch (value) {
                        case 0:
                            return "<span style='color: #f30'>待审核</span>";
                        case 1:
                            return "<span style='color: #00aa00'>已提现</span>";
                        case -1:
                            return "<span style='color: #EFB808'>未通过</span>";
                    }
                },
                type:function (value, row, index) {
                    switch (value) {
                        case 1:
                            return "微信";
                        case 2:
                            return "支付宝";
                        case 3:
                            return "银行卡";
                    }
                },
                message:function (value, row, index) {
                    switch (row.type) {
                        case 1:
                            return "微信号："+row.wechat;
                        case 2:
                            return "支付宝姓名："+row.alipay_name+"<br/>"+"支付宝账号："+row.alipay;
                        case 3:
                            return "开户行："+row.bank_name+"<br/>"
                                +"银行卡号:"+row.bank_code+"<br/>"
                                +"账户名称:"+row.name;
                    }
                }
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});